package com.liberty.dasheen.admin.daily.service.impl;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liberty.dasheen.admin.daily.service.DailyOrderService;
import com.liberty.dasheen.common.util.DateUtil;
import com.liberty.dasheen.common.util.SafeUtil;
import com.liberty.dasheen.common.util.SearchFilter;
import com.liberty.dasheen.entity.DailyOrder;
import com.liberty.dasheen.mapper.DailyOrderMapper;
import com.liberty.dasheen.vo.DailyOrderVo;

@Service
public class DailyOrderServiceImpl implements DailyOrderService {

	@Autowired
	private DailyOrderMapper dailyOrderMapper;
	
	@Override
	public DailyOrder addOrder(DailyOrder order, HttpSession session) {
		Date now = new Date();
		String dailyOrderNo = DateUtil.getCompactLongStr(now);
		order.setDailyOrderNo(dailyOrderNo);
		order.setCreateUserId(SafeUtil.getUserId(session));
		order.setCreateTime(now);
		order.setUpdateUserId(SafeUtil.getUserId(session));
		order.setUpdateTime(now);
		order.setIsDelete(0);
		order.setIsPay(0);
		Integer dailyOrderId = dailyOrderMapper.addOrder(order);
		order.setDailyOrderId(dailyOrderId);
		return order;
	}

	@Override
	public void deleteOrder(Object ids, HttpSession session) {
		String[] idsArr = StringUtils.split(String.valueOf(ids), ",");
		dailyOrderMapper.deleteOrder(idsArr);
	}
	
	@Override
	public DailyOrder updateOrder(DailyOrder order, HttpSession session) {
		Date now = new Date();
		order.setUpdateUserId(SafeUtil.getUserId(session));
		order.setUpdateTime(now);
		dailyOrderMapper.updateOrder(order);
		return order;
	}
	@Override
	public List<DailyOrderVo> list(SearchFilter filter) {
		return dailyOrderMapper.list(filter);
	}

	@Override
	public Integer count(SearchFilter filter) {
		return dailyOrderMapper.count(filter);
	}

}
